9 bool operator < (const Point
&p
) const {
10 return (x
< p
.x
|| (x
== p
.x
&& y
< p
.y
));
15 // Return a positive value, if OAB makes a counter-clockwise turn,
16 // negative for clockwise turn, and zero if the points are collinear.
17 int cross(const Point
&O
, const Point
&A
, const Point
&B
)
19 return (A
.x
- O
.x
) * (B
.y
- O
.y
) - (A
.y
- O
.y
) * (B
.x
- O
.x
);
22 // Returns a list of points on the convex hull in counter-clockwise order.
23 // Note: the last point in the returned list is the same as the first one.
24 vector
<Point
> convexHull(vector
<Point
> P
)
26 int n
= P
.size(), k
= 0;
29 // Sort Points lexicographically
30 sort(P
.begin(), P
.end());
33 for (int i
= 0; i
< n
; i
++) {
34 while (k
>= 2 && cross(H
[k
-2], H
[k
-1], P
[i
]) <= 0) k
--;
39 for (int i
= n
-2, t
= k
+1; i
>= 0; i
--) {
40 while (k
>= t
&& cross(H
[k
-2], H
[k
-1], P
[i
]) <= 0) k
--;
48 void printPnt(const Point
&p
){
49 cout
<< "(" << p
.x
<< "," << p
.y
<< ")";
58 for (int i
=0; i
<n
; ++i
){
64 /*cout << "g.size() es: " << g.size() << endl;
65 for (int i=0; i<n; ++i){
70 vector
<Point
> chull
= convexHull(g
);
71 /*cout << "chull.size() es: " << chull.size() << endl;
72 for (int i=0; i<chull.size(); ++i){
78 if (chull
.size() == n
){